package com.dodoke.ojserver.service.impl;

import com.dodoke.ojserver.bean.Users;
import com.dodoke.ojserver.bean.dto.UsersDTO;
import com.dodoke.ojserver.mapper.UsersMapper;
import com.dodoke.ojserver.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UsersServiceImpl implements IUsersService {
    @Autowired(required=false)
    private UsersMapper usersMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public Users login(UsersDTO usersDTO) {
        Users u = usersMapper.getUsersByNameAndPassword(usersDTO);
        if(u!=null){
            return u;
        }
        throw  new RuntimeException("认证失败~~");
    }

    @Override
    public Users findUserById(String id) {
        return usersMapper.findUserById(id);
    }
}
